.class public Lcom/ocpsoft/pretty/time/BasicTimeFormat;
.super Ljava/lang/Object;
.source "BasicTimeFormat.java"

# interfaces
.implements Lcom/ocpsoft/pretty/time/TimeFormat;


# static fields
.field private static final NEGATIVE:Ljava/lang/String; = "-"

.field public static final QUANTITY:Ljava/lang/String; = "%n"

.field public static final SIGN:Ljava/lang/String; = "%s"

.field public static final UNIT:Ljava/lang/String; = "%u"


# instance fields
.field private futurePrefix:Ljava/lang/String;

.field private futureSuffix:Ljava/lang/String;

.field private pastPrefix:Ljava/lang/String;

.field private pastSuffix:Ljava/lang/String;

.field private pattern:Ljava/lang/String;

.field private roundingTolerance:I


# direct methods
.method public constructor <init>()V
    .locals 1

    .prologue
    .line 28
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 35
    const-string v0, ""

    iput-object v0, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->pattern:Ljava/lang/String;

    .line 36
    const-string v0, ""

    iput-object v0, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->futurePrefix:Ljava/lang/String;

    .line 37
    const-string v0, ""

    iput-object v0, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->futureSuffix:Ljava/lang/String;

    .line 38
    const-string v0, ""

    iput-object v0, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->pastPrefix:Ljava/lang/String;

    .line 39
    const-string v0, ""

    iput-object v0, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->pastSuffix:Ljava/lang/String;

    .line 40
    const/16 v0, 0x32

    iput v0, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->roundingTolerance:I

    return-void
.end method

.method private applyPattern(Ljava/lang/String;Ljava/lang/String;J)Ljava/lang/String;
    .locals 3
    .parameter "sign"
    .parameter "unit"
    .parameter "quantity"

    .prologue
    .line 69
    iget-object v1, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->pattern:Ljava/lang/String;

    const-string v2, "%s"

    invoke-virtual {v1, v2, p1}, Ljava/lang/String;->replaceAll(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    .line 70
    .local v0, result:Ljava/lang/String;
    const-string v1, "%n"

    invoke-static {p3, p4}, Ljava/lang/String;->valueOf(J)Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v0, v1, v2}, Ljava/lang/String;->replaceAll(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    .line 71
    const-string v1, "%u"

    invoke-virtual {v0, v1, p2}, Ljava/lang/String;->replaceAll(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    .line 72
    return-object v0
.end method

.method private decorate(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    .locals 2
    .parameter "sign"
    .parameter "result"

    .prologue
    .line 56
    const-string v0, "-"

    invoke-virtual {v0, p1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v0

    if-eqz v0, :cond_0

    .line 58
    new-instance v0, Ljava/lang/StringBuilder;

    invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V

    iget-object v1, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->pastPrefix:Ljava/lang/String;

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    const-string v1, " "

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0, p2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    const-string v1, " "

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    iget-object v1, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->pastSuffix:Ljava/lang/String;

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p2

    .line 64
    :goto_0
    const-string v0, "\\s+"

    const-string v1, " "

    invoke-virtual {p2, v0, v1}, Ljava/lang/String;->replaceAll(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/String;->trim()Ljava/lang/String;

    move-result-object v0

    return-object v0

    .line 62
    :cond_0
    new-instance v0, Ljava/lang/StringBuilder;

    invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V

    iget-object v1, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->futurePrefix:Ljava/lang/String;

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    const-string v1, " "

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0, p2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    const-string v1, " "

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    iget-object v1, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->futureSuffix:Ljava/lang/String;

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p2

    goto :goto_0
.end method

.method private getGramaticallyCorrectName(Lcom/ocpsoft/pretty/time/Duration;)Ljava/lang/String;
    .locals 5
    .parameter "d"

    .prologue
    .line 93
    invoke-virtual {p1}, Lcom/ocpsoft/pretty/time/Duration;->getUnit()Lcom/ocpsoft/pretty/time/TimeUnit;

    move-result-object v1

    invoke-interface {v1}, Lcom/ocpsoft/pretty/time/TimeUnit;->getName()Ljava/lang/String;

    move-result-object v0

    .line 94
    .local v0, result:Ljava/lang/String;
    invoke-direct {p0, p1}, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->getQuantity(Lcom/ocpsoft/pretty/time/Duration;)J

    move-result-wide v1

    invoke-static {v1, v2}, Ljava/lang/Math;->abs(J)J

    move-result-wide v1

    const-wide/16 v3, 0x0

    cmp-long v1, v1, v3

    if-eqz v1, :cond_0

    invoke-direct {p0, p1}, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->getQuantity(Lcom/ocpsoft/pretty/time/Duration;)J

    move-result-wide v1

    invoke-static {v1, v2}, Ljava/lang/Math;->abs(J)J

    move-result-wide v1

    const-wide/16 v3, 0x1

    cmp-long v1, v1, v3

    if-lez v1, :cond_1

    .line 96
    :cond_0
    invoke-virtual {p1}, Lcom/ocpsoft/pretty/time/Duration;->getUnit()Lcom/ocpsoft/pretty/time/TimeUnit;

    move-result-object v1

    invoke-interface {v1}, Lcom/ocpsoft/pretty/time/TimeUnit;->getPluralName()Ljava/lang/String;

    move-result-object v0

    .line 98
    :cond_1
    return-object v0
.end method

.method private getQuantity(Lcom/ocpsoft/pretty/time/Duration;)J
    .locals 8
    .parameter "duration"

    .prologue
    .line 77
    invoke-virtual {p1}, Lcom/ocpsoft/pretty/time/Duration;->getQuantity()J

    move-result-wide v4

    invoke-static {v4, v5}, Ljava/lang/Math;->abs(J)J

    move-result-wide v0

    .line 79
    .local v0, quantity:J
    invoke-virtual {p1}, Lcom/ocpsoft/pretty/time/Duration;->getDelta()J

    move-result-wide v4

    const-wide/16 v6, 0x0

    cmp-long v4, v4, v6

    if-eqz v4, :cond_0

    .line 81
    invoke-virtual {p1}, Lcom/ocpsoft/pretty/time/Duration;->getDelta()J

    move-result-wide v4

    long-to-double v4, v4

    invoke-virtual {p1}, Lcom/ocpsoft/pretty/time/Duration;->getUnit()Lcom/ocpsoft/pretty/time/TimeUnit;

    move-result-object v6

    invoke-interface {v6}, Lcom/ocpsoft/pretty/time/TimeUnit;->getMillisPerUnit()J

    move-result-wide v6

    long-to-double v6, v6

    div-double/2addr v4, v6

    const-wide/high16 v6, 0x4059

    mul-double/2addr v4, v6

    invoke-static {v4, v5}, Ljava/lang/Math;->abs(D)D

    move-result-wide v2

    .line 83
    .local v2, threshold:D
    iget v4, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->roundingTolerance:I

    int-to-double v4, v4

    cmpl-double v4, v2, v4

    if-lez v4, :cond_0

    .line 85
    const-wide/16 v4, 0x1

    add-long/2addr v0, v4

    .line 88
    .end local v2           #threshold:D
    :cond_0
    return-wide v0
.end method

.method private getSign(Lcom/ocpsoft/pretty/time/Duration;)Ljava/lang/String;
    .locals 4
    .parameter "d"

    .prologue
    .line 103
    invoke-virtual {p1}, Lcom/ocpsoft/pretty/time/Duration;->getQuantity()J

    move-result-wide v0

    const-wide/16 v2, 0x0

    cmp-long v0, v0, v2

    if-gez v0, :cond_0

    .line 105
    const-string v0, "-"

    .line 107
    :goto_0
    return-object v0

    :cond_0
    const-string v0, ""

    goto :goto_0
.end method


# virtual methods
.method public format(Lcom/ocpsoft/pretty/time/Duration;)Ljava/lang/String;
    .locals 5
    .parameter "duration"

    .prologue
    .line 44
    invoke-direct {p0, p1}, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->getSign(Lcom/ocpsoft/pretty/time/Duration;)Ljava/lang/String;

    move-result-object v3

    .line 45
    .local v3, sign:Ljava/lang/String;
    invoke-direct {p0, p1}, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->getGramaticallyCorrectName(Lcom/ocpsoft/pretty/time/Duration;)Ljava/lang/String;

    move-result-object v4

    .line 46
    .local v4, unit:Ljava/lang/String;
    invoke-direct {p0, p1}, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->getQuantity(Lcom/ocpsoft/pretty/time/Duration;)J

    move-result-wide v0

    .line 48
    .local v0, quantity:J
    invoke-direct {p0, v3, v4, v0, v1}, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->applyPattern(Ljava/lang/String;Ljava/lang/String;J)Ljava/lang/String;

    move-result-object v2

    .line 49
    .local v2, result:Ljava/lang/String;
    invoke-direct {p0, v3, v2}, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->decorate(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    .line 51
    return-object v2
.end method

.method public getFuturePrefix()Ljava/lang/String;
    .locals 1

    .prologue
    .line 166
    iget-object v0, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->futurePrefix:Ljava/lang/String;

    return-object v0
.end method

.method public getFutureSuffix()Ljava/lang/String;
    .locals 1

    .prologue
    .line 171
    iget-object v0, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->futureSuffix:Ljava/lang/String;

    return-object v0
.end method

.method public getPastPrefix()Ljava/lang/String;
    .locals 1

    .prologue
    .line 176
    iget-object v0, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->pastPrefix:Ljava/lang/String;

    return-object v0
.end method

.method public getPastSuffix()Ljava/lang/String;
    .locals 1

    .prologue
    .line 181
    iget-object v0, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->pastSuffix:Ljava/lang/String;

    return-object v0
.end method

.method public getPattern()Ljava/lang/String;
    .locals 1

    .prologue
    .line 161
    iget-object v0, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->pattern:Ljava/lang/String;

    return-object v0
.end method

.method public getRoundingTolerance()I
    .locals 1

    .prologue
    .line 186
    iget v0, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->roundingTolerance:I

    return v0
.end method

.method public setFuturePrefix(Ljava/lang/String;)Lcom/ocpsoft/pretty/time/BasicTimeFormat;
    .locals 1
    .parameter "futurePrefix"

    .prologue
    .line 121
    invoke-virtual {p1}, Ljava/lang/String;->trim()Ljava/lang/String;

    move-result-object v0

    iput-object v0, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->futurePrefix:Ljava/lang/String;

    .line 122
    return-object p0
.end method

.method public setFutureSuffix(Ljava/lang/String;)Lcom/ocpsoft/pretty/time/BasicTimeFormat;
    .locals 1
    .parameter "futureSuffix"

    .prologue
    .line 127
    invoke-virtual {p1}, Ljava/lang/String;->trim()Ljava/lang/String;

    move-result-object v0

    iput-object v0, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->futureSuffix:Ljava/lang/String;

    .line 128
    return-object p0
.end method

.method public setPastPrefix(Ljava/lang/String;)Lcom/ocpsoft/pretty/time/BasicTimeFormat;
    .locals 1
    .parameter "pastPrefix"

    .prologue
    .line 133
    invoke-virtual {p1}, Ljava/lang/String;->trim()Ljava/lang/String;

    move-result-object v0

    iput-object v0, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->pastPrefix:Ljava/lang/String;

    .line 134
    return-object p0
.end method

.method public setPastSuffix(Ljava/lang/String;)Lcom/ocpsoft/pretty/time/BasicTimeFormat;
    .locals 1
    .parameter "pastSuffix"

    .prologue
    .line 139
    invoke-virtual {p1}, Ljava/lang/String;->trim()Ljava/lang/String;

    move-result-object v0

    iput-object v0, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->pastSuffix:Ljava/lang/String;

    .line 140
    return-object p0
.end method

.method public setPattern(Ljava/lang/String;)Lcom/ocpsoft/pretty/time/BasicTimeFormat;
    .locals 0
    .parameter "pattern"

    .prologue
    .line 115
    iput-object p1, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->pattern:Ljava/lang/String;

    .line 116
    return-object p0
.end method

.method public setRoundingTolerance(I)Lcom/ocpsoft/pretty/time/BasicTimeFormat;
    .locals 0
    .parameter "roundingTolerance"

    .prologue
    .line 151
    iput p1, p0, Lcom/ocpsoft/pretty/time/BasicTimeFormat;->roundingTolerance:I

    .line 152
    return-object p0
.end method
